﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pata.SylkSharp.Core.Bll
{

    /// <summary>
    /// Enumerates the possible fields in a <see cref="ORecord"/>
    /// </summary>
    public enum ORecordFieldType
    {
        /// <summary>
        /// Contains iter and delta
        /// If present, allow value iteration
        /// If absent, circular references are not allowed.
        ///     iter (maximum number of iterations)
        ///     delta (step test. If smaller, then finished.)
        /// </summary>
        A,
        /// <summary>
        /// completion test at nearest preceding C record
        /// </summary>
        C,
        /// <summary>
        /// sheet is protected
        /// </summary>
        P,
        /// <summary>
        /// use A1 mode references
        /// Even if ;L is given R1C1 references are used in SYLK file expressions.
        /// </summary>
        L,
        /// <summary>
        /// If present, use manual recalculation.
        /// If absent, use automatic recalculation.
        /// </summary>
        M,
        /// <summary>
        /// Macro sheet.
        /// This should appear before the first appearance of a ;G or ;F field in a NN record.
        /// This should appear before the first C record which uses a macro-only function.
        /// </summary>
        E,
        /// <summary>
        /// value indicates the base date used for calculating serial date values
        ///      0       01 January 1900
        ///      4       01 January 1904
        /// </summary>
        V,
        /// <summary>
        /// Unknown field type.
        /// </summary>
        Unknown = 100
    }

    /// <summary>
    /// Object representation of field of a Sylk record of type 'O'
    /// </summary>
    public class ORecordField : FieldBase<ORecordFieldType>
    {
        /// <summary>
        /// Instanciate a new <see cref="ORecordField"/>
        /// </summary>
        public ORecordField()
            : base(ORecordFieldType.Unknown, String.Empty) { }

        /// <summary>
        /// Instanciate a new <see cref="ORecordField"/>
        /// </summary>
        /// <param name="pType">Type of this field.</param>
        /// <param name="pValue">The value contained by this field.</param>
        public ORecordField(ORecordFieldType pType, string pValue)
            : base(pType, pValue) { }
    }

    /// <summary>
    /// Object representation of a Sylk record of type 'O', Options
    /// </summary>
    public class ORecord : RecordBase<ORecordField, ORecordFieldType>
    {
        //TODO:Complete this array.
        private static readonly ORecordFieldType[] _MANDATORY_FIELDS = new ORecordFieldType[] { };

        /// <summary>
        /// Instanciate a new <see cref="ORecord"/>
        /// </summary>
        public ORecord(string pLineWithoutId)
            : base(RecordType.O, pLineWithoutId, ORecordFieldType.Unknown) { }

        /// <summary>
        /// Get mandatory fields for this record.
        /// </summary>
        /// <returns></returns>
        public override System.Collections.Generic.IEnumerable<ORecordFieldType> GetMandatoryFields()
        {
            return _MANDATORY_FIELDS;
        }

        /// <summary>
        /// Get the default field type.
        /// </summary>
        /// <returns></returns>
        public override ORecordFieldType GetUnknownFieldType()
        {
            return ORecordFieldType.Unknown;
        }
    }
}
